<template>
    <div>
        <ul>
            <li v-for="(item,index) in order_list" :key="index">
                <img :src="'http://localhost:8000/static/upload/' + item.img " width="50" >

                名字：{{ item.username }} &nbsp;&nbsp;&nbsp;&nbsp;

                数量：{{ item.num}} &nbsp;&nbsp;&nbsp;&nbsp;

                收货人：{{item.s_name}}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

                金额：{{ item.price}}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

                <div v-if="if_pl==1">
                    
                    <button  >已经评论</button>
                    <button @click="index_pl(item.id)"  >查看评论</button>
                </div>

                <div v-else>
                    <button @click="if_login" >评论</button>
                </div>
                

            </li>
        </ul>
    </div>
</template>



<script>
export default {
    data(){
        return{
            order_list:[],
            if_pl:'',
        }
    },
    mounted() {
        //获取顶顶那
        this.get_order()
        //判断评论
        this.if_p()

        // if(localStorage.getItem('uid')){
        //     this.if_pl=1
        // }else{
        //     this.if_p=0
        // }
    },
    methods: {
        //查看评论
        index_pl(order_id){
            // console.log(order_id)
            for(let i=0,l=this.order_list.length;i<l;i++){
                // console.log(this.order_list[i].id==order_id)
                if(this.order_list[i].id==order_id){
                    // console.log(this.order_list[i])
                    localStorage.setItem('order',JSON.stringify(this.order_list[i]))
                }
            }

            this.$router.push('/indexpl')
        },
        //判断是否pl
        if_p(){
            if(localStorage.getItem('pl')){
                this.if_pl = 1
            }else{
                this.if_pl=0
            }
        },
        //判断是否登录
        if_login(){
            if (localStorage.getItem('uid')){
                this.$router.push('/mypl')
            }else{
                alert('请先登录')
                this.$router.push('/mylogin')
                
            }
        },
        // 获取订单
        get_order(){
            this.axios.get('http://localhost:8000/order/').then(res=>{
                console.log(res)
                this.order_list = res.data
            })
        }
        
    },
}
</script>